#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->zx->setText("0");
    ui->zy->setText("0");
    ui->yx->setText("512");
    ui->yy->setText("512");
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::on_pushButton_5_clicked()
{
    QString OpenFile, OpenFilePath;
    QImage image;
    //打开文件夹中的图片文件
    OpenFile = QFileDialog::getOpenFileName(this,
                                            "Please choose an image file",
                                            "",
                                            "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)");

    if( OpenFile != "" )
    {
        if( image.load(OpenFile) )
        {
            ui->label_5->setPixmap(QPixmap::fromImage(image));
        }
    }
    //显示所示图片的路径
    QFileInfo OpenFileInfo;
    OpenFileInfo = QFileInfo(OpenFile);
    OpenFilePath = OpenFileInfo.filePath();
     ui->lineEdit_9->setText(OpenFilePath);

    QByteArray ba = OpenFilePath.toLatin1(); // must
    const char *readTemp=ba.data();//读取图片路径
    image1.ReadBMP(readTemp);
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);

}
void MainWindow::on_pushButton_6_clicked()//保存图片
{
    //该函数返回用户所设定的包含文件名的目录
    QString fileName = QFileDialog::getSaveFileName(
                this,
                tr("Save File"),
                "/home/untitled.png",
                tr("Images (*.bmp *.xpm *.jpg)"));//多组扩展名用双分号";;"隔开
    QFileInfo OpenFileInfo;
    OpenFileInfo = QFileInfo(fileName);
    QByteArray ba = fileName.toLatin1(); // must
    const char *readTemp=ba.data();//读取图片路径
    image1.WriteBMP(readTemp);
    QMessageBox::information(this,"提示信息","保存完成");

}
void MainWindow::on_pushButton_9_clicked()//90度旋转
{
    image1.Rotate(90);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","旋转90完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}
void MainWindow::on_pushButton_10_clicked()//180度旋转
{
    image1.Rotate(180);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","旋转180完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);

}



void MainWindow::on_pushButton_11_clicked()//270度旋转
{
    image1.Rotate(270);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","旋转270完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);

}



void MainWindow::on_pushButton_clicked()//上下翻转
{
    image1.Flip(1);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","上下翻转 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);

}



void MainWindow::on_pushButton_2_clicked()//左右旋转
{
    image1.Flip(0);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","上下翻转 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}



void MainWindow::on_pushButton_15_clicked()//左右拼接
{
    QString OpenFile, OpenFilePath;
    QImage image;
    //打开文件夹中的图片文件
    OpenFile = QFileDialog::getOpenFileName(this,
                                            "Please choose an image file",
                                            "",
                                            "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)");

    if( OpenFile != "" )
    {
        if( image.load(OpenFile) )
        {
            ui->label_6->setPixmap(QPixmap::fromImage(image));
        }
    }
    //显示所示图片的路径
    QFileInfo OpenFileInfo;
    OpenFileInfo = QFileInfo(OpenFile);
    OpenFilePath = OpenFileInfo.filePath();
    ui->lineEdit_10->setText(OpenFilePath);
    QByteArray ba = OpenFilePath.toLatin1(); // must
    const char *readTemp=ba.data();//读取图片路径

    image2.ReadBMP(readTemp);
    image1.Jpint(image2,0);
    QImage imagee(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(imagee));
    image1.ReadBMP(readTemp);
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}



void MainWindow::on_pushButton_13_clicked()//上下拼接
{
    QString OpenFile, OpenFilePath;
    QImage image;
    //打开文件夹中的图片文件
    OpenFile = QFileDialog::getOpenFileName(this,
                                            "Please choose an image file",
                                            "",
                                            "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)");

    if( OpenFile != "" )
    {
        if( image.load(OpenFile) )
        {
            ui->label_6->setPixmap(QPixmap::fromImage(image));
        }
    }
    //显示所示图片的路径
    QFileInfo OpenFileInfo;
    OpenFileInfo = QFileInfo(OpenFile);
    OpenFilePath = OpenFileInfo.filePath();
    ui->lineEdit_10->setText(OpenFilePath);
    QByteArray ba = OpenFilePath.toLatin1(); // must
    const char *readTemp=ba.data();//读取图片路径

    image2.ReadBMP(readTemp);
    image1.Jpint(image2,1);
    QImage imagee(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(imagee));
    image1.ReadBMP(readTemp);
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}
void MainWindow::on_pushButton_3_clicked()//缩小
{
    image1.Resize(0);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","缩小 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}



void MainWindow::on_pushButton_4_clicked()//放大
{
    image1.Resize(1);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","放大 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}



void MainWindow::on_pushButton_7_clicked()//灰化
{
    image1.gray();
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","灰化 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}
void MainWindow::on_pushButton_8_clicked()//设置同一值
{
    image1.Set(10);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","同一值 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}
void MainWindow::on_pushButton_16_clicked()//边缘检测
{
    image1.bianyuan();
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
    QMessageBox::information(this,"提示信息","边缘检测 完成");
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
}



void MainWindow::on_pushButton_14_clicked()//裁剪
{
    QString x1=ui->zx->text();
    QString y1=ui->zy->text();
    QString x2=ui->yx->text();
    QString y2=ui->yy->text();
    int x_1=x1.toInt();
    int y_1=y1.toInt();
    int x_2=x2.toInt();
    int y_2=y2.toInt();
    image1.Cut(x_1,y_1,x_2,y_2);
    int h=image1.Height();
    int w=image1.Width();
    QString h_1=QString::number(h);
    QString w_1=QString::number(w);
    ui->lineEdit_5->setText(h_1);
    ui->lineEdit_6->setText(w_1);
    float a,b;
    image1.Mean_Variance(a,b);
    QString f_1=QString::number(a);
    QString j_1=QString::number(b);
    ui->lineEdit_7->setText(j_1);
    ui->lineEdit_8->setText(f_1);
    QImage image(image1);
    ui->label_7->setPixmap(QPixmap::fromImage(image));
}



